package net;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

import logic.GameRules;
import logic.Manager;

public class GameServer implements Runnable{
	public GameRules gameRules;
	public Socket socket;
	public Thread serverThread;
	public ServerSocket server;
	public Manager gameManager;
	public int state;
	
	final static int INIT_SERVER = 0;
	final static int WAIT_CONNECTIONS = INIT_SERVER + 1;
	final static int IN_GAME = WAIT_CONNECTIONS + 1;
	final static int CLOSE = IN_GAME + 1;
	
	public GameServer(){
		state = INIT_SERVER;
		gameManager = new Manager(2);
		gameRules = new GameRules();
		serverThread = new Thread(this);
		serverThread.start();
	}
	
	public void initServer(){
		try{
			server = new ServerSocket(9999);
			socket = server.accept();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void run() {
		while(Thread.currentThread().equals(serverThread)){
			switch(state){
				case INIT_SERVER:
					initServer();
					state = WAIT_CONNECTIONS;
					break;
				case WAIT_CONNECTIONS:
					break;
				case IN_GAME:
					break;
				case CLOSE:
					serverThread.interrupt();
					break;
			}
		}
	}
}
